// zh_gjw/pages/order/info.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    options.img = options.img.split(',')
		var siteUrl = wx.getStorageSync('siteUrl')
    that.setData({
      info:options,
      siteUrl: siteUrl
    })
  },


  // 抖宝的商品支付
  dbpay: function (e) {
    
    var that=this
    var openid = wx.getStorageSync('openid')
    var res_id = that.data.info.id
    var ofees = that.data.info.ofees
    app.util.request({
      url: 'entry/wxapp/Dborderpay',
      data: {
        openid: openid, res_id: res_id, ofees: ofees
      },
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': 'MD5',
          'paySign': res.data.paySign,
          'success': function (res) {
            app.util.request({
              url: 'entry/wxapp/Dborderpaysuccess',
              data: {
                res_id: res_id
              },
              success: function (res) {
                wx.showModal({
                  title: '提示',
                  content: '您的订单已经付款成功,商家会尽快为您发货哦',
                  showCancel: false,
                  cancelColor: '',
                  confirmText: '我知道了',
                  confirmColor: '',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateTo({
                        url: '../order/index',
                      })
                    } else if (res.cancel) {
                    }
                  },
                  fail: function (res) { },
                  complete: function (res) { },
                })

              }
            })

          },
          'fail': function (res) {
            
            wx.showToast({
              title: '支付失败',
              icon: "loading",
            })
          },
          'complete': function (res) {
            
            wx.showToast({
              title: '取消支付',
              icon: "loading",
            })
          }
        })

      }

    })
  },


  // 微拍的商品支付
  wppay: function (e) {
    
    var that = this    
    var openid = wx.getStorageSync('openid')
    var res_id = that.data.info.id
    var g_id = that.data.info
    var ofees = that.data.info.ofees
    app.util.request({
      url: 'entry/wxapp/Shotorderpay',
      data: {
        openid: openid, res_id: res_id, ofees: ofees
      },
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': 'MD5',
          'paySign': res.data.paySign,
          'success': function (res) {
            app.util.request({
              url: 'entry/wxapp/Shotorderpaysuccess',
              data: {
                res_id: res_id, p_id: g_id
              },
              success: function (res) {
                wx.showModal({
                  title: '提示',
                  content: '您的订单已经付款成功,商家会尽快为您发货哦',
                  showCancel: false,
                  cancelColor: '',
                  confirmText: '我知道了',
                  confirmColor: '',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateTo({
                        url: '../order/index',
                      })
                    } else if (res.cancel) {
                    }
                  },
                  fail: function (res) { },
                  complete: function (res) { },
                })

              }
            })

          },
          'fail': function (res) {
            
            wx.showToast({
              title: '支付失败',
              icon: "loading",
            })
          },
          'complete': function (res) {
            
            wx.showToast({
              title: '取消支付',
              icon: "loading",
            })
          }
        })

      }

    })
  },



  // 集市的商品支付
  jspay: function (e) {
    
    var that = this    
    var openid = wx.getStorageSync('openid')
    var res_id = that.data.info.id
    var g_id=that.data.info
    var ofees = that.data.info.ofees
    app.util.request({
      url: 'entry/wxapp/Marketorderpay',
      data: {
        openid: openid, res_id: res_id, ofees: ofees
      },
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': 'MD5',
          'paySign': res.data.paySign,
          'success': function (res) {
            app.util.request({
              url: 'entry/wxapp/Marketorderpaysuccess',
              data: {
                res_id: res_id, p_id: g_id
              },
              success: function (res) {
                wx.showModal({
                  title: '提示',
                  content: '您的订单已经付款成功,商家会尽快为您发货哦',
                  showCancel: false,
                  cancelColor: '',
                  confirmText: '我知道了',
                  confirmColor: '',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateTo({
                        url: '../order/index',
                      })
                    } else if (res.cancel) {
                    }
                  },
                  fail: function (res) { },
                  complete: function (res) { },
                })

              }
            })

          },
          'fail': function (res) {
            
            wx.showToast({
              title: '支付失败',
              icon: "loading",
            })
          },
          'complete': function (res) {
            
            wx.showToast({
              title: '取消支付',
              icon: "loading",
            })
          }
        })

      }

    })
  },

  // 商店的商品支付
  sdpay: function (e) {
    
    var that = this
    var openid = wx.getStorageSync('openid')
    var res_id = that.data.info.id
    var g_id = that.data.info
    var ofees = that.data.info.ofees
    app.util.request({
      url: 'entry/wxapp/Storeorderpay',
      data: {
        openid: openid, res_id: res_id, ofees: ofees
      },
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr,
          'package': res.data.package,
          'signType': 'MD5',
          'paySign': res.data.paySign,
          'success': function (res) {
            app.util.request({
              url: 'entry/wxapp/Storeorderpaysuccess',
              data: {
                res_id: res_id, p_id: g_id
              },
              success: function (res) {
                wx.showModal({
                  title: '提示',
                  content: '您的订单已经付款成功,商家会尽快为您发货哦',
                  showCancel: false,
                  cancelColor: '',
                  confirmText: '我知道了',
                  confirmColor: '',
                  success: function (res) {
                    if (res.confirm) {
                      wx.navigateTo({
                        url: '../order/index',
                      })
                    } else if (res.cancel) {
                    }
                  },
                  fail: function (res) { },
                  complete: function (res) { },
                })

              }
            })

          },
          'fail': function (res) {
            
            wx.showToast({
              title: '支付失败',
              icon: "loading",
            })
          },
          'complete': function (res) {
            
          }
        })

      }

    })
  },


  waite: function (e) {
    wx.showModal({
      title: '提示',
      content: '您的订单将在72小时内为您发货，请耐心等待...',
      showCancel: false,
      confirmText: '我知道了',
      success: function (res) {
        if (res.confirm) {
          
        } else if (res.cancel) {
          
        }
      }
    })
  },

  // 确认收货
  get_gift: function (e) {
    var that = this
    
    var res_id = that.data.info.id
    var g_id = that.data.info.p_id
    var cusname = that.data.info.cusname
    wx.showModal({
      title: '提示',
      content: '是否确认收到宝贝，并且验收完好？',
      success: function (res) {
        if (res.confirm) {
          
          app.util.request({
            url: 'entry/wxapp/Usersh',
            data: {
              res_id: res_id,
            },
            success: function (res) {
              
              wx.showModal({
                title: '提示',
                content: '您已成功收货，去给店铺评个分吧',
                success: function (res) {
                  if (res.confirm) {
                    wx.navigateTo({
                      url: '../order/comment?id=' + res_id + '&p_id=' + g_id + '&cusname=' + cusname
                    })
                  }
                }
              })
            }
          })
        } else if (res.cancel) {
          
        }
      }
    })

  },

  // 删除订单
  delete: function (e) {
    var that = this
    
    var res_id = that.data.info.id
    wx.showModal({
      title: '提示',
      content: '是否确定删除该订单？',
      success: function (res) {
        if (res.confirm) {
          
          app.util.request({
            url: 'entry/wxapp/Orderdelete',
            data: {
              id: res_id,
            },
            success: function (res) {
              
              wx.navigateTo({
                url: '../order/index',
              })   
              wx.showToast({
                title: '已成功删除',
              })
            }
          })
        } else if (res.cancel) {
          
        }
      }
    })

  },  

  go_pl:function(e){
    var that=this
    var id = that.data.info.id
    var p_id = that.data.info.p_id
    var cusname = that.data.info.cusname
    wx.navigateTo({
      url: '../order/comment?id='+id+'&p_id='+p_id+'&cusname='+cusname,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})